/*
 * Created by Jaren at 2023/9/4 14:56
 */
import 'dart:typed_data';

import 'package:binary/binary.dart';
import 'package:inmotion_protocol/ezcan/bean/settings.dart';
import 'package:inmotion_protocol/util/byte_util.dart';

class R1Settings extends AbsSettings {
  Uint8 language = Uint8.zero;
  Uint4 gps = Uint4.zero;
  Uint32 speedLimit = Uint32.zero;
  Uint8 volume = Uint8.zero;
  Uint32 turningSensitivity = Uint32.zero;
  Int32 angleZ = Int32.zero;

  R1Settings.fromSlowRspMsg(Uint8ClampedList bytes) {
    speedLimit = ByteUtil.toUint32(ByteUtil.bytes2Uint32Le(bytes, 60).value ~/ 38.12);

    if (bytes.length > 56) angleZ = ByteUtil.toInt32(ByteUtil.bytes2Int32Le(bytes, 56).value ~/ 655.36); // angleZ: [-500, 500]
    if (bytes.length > 72) turningSensitivity = ByteUtil.bytes2Uint32Le(bytes, 72); // turning sensitivity: [20, 200]
    if (bytes.length > 88) gps = ByteUtil.toUint4(ByteUtil.bytes2UIntLe(bytes, 88));
  }

  @override
  String toString() {
    return 'R1Settings{language: $language, gps: $gps, speedLimit: $speedLimit, volume: $volume, turningSensitivity: $turningSensitivity, angleZ: $angleZ}';
  }
}
